<!DOCTYPE html>
<html lang="zh-cmn-Hans">
	<head>
		<title>文件上传</title>
		<meta charset="UTF-8" />
		<link rel="stylesheet" href="../../lib/bootstrap/css/bootstrap.min.css" />
		<link rel="stylesheet" href="../../lib/font-awesome-4.0.3/css/font-awesome.min.css" />
		<style>
			html, body {
				height: 100%;
			}
			.container {
				width: 350px;
				margin-left: auto;
				margin-right: auto;
			}
			.title {
				margin-left: auto;
				margin-right: auto;
				height: 100px;
				line-height: 100px;
				width: 100%;
				font-size: 26px;
				text-align: center;
				color: #47a447;
			}
			.file-upload {
				width: 100%;
			}
			.file-upload i {
				font-size: 125px;
				display: block;
				height: 150px;
				line-height: 150px;
				width: 100%;
				text-align: center;
			}
			.file-upload i:hover {
				color: #3276b1;
			}
		</style>
	</head>
	<body style="background-color: #fff!important;">
		<div class="container">
			<div class="title" style="display: none;">
				<i class="glyphicon glyphicon-info-sign"></i>
				<span>文件上传成功</span>
			</div>
			<form id="form" method="post" enctype="multipart/form-data" action="../../project/upload.koala" style="margin-left: 5%;margin-right: 5%;">
				<div class="content">
					<div class="file-upload">
						<i class="fa fa-cloud-upload" id="fileImg"></i>
						<input id="file" name="file" type="file" style="display: none;"/>
						<div class="file-name" id="fileName"></div>
					</div>
					<button type="button" class="btn btn-primary btn-block" id="uploadBtn">
						重新上传
					</button>
					<input type="hidden" id="timestamp" name="timestamp">
					</input>
				</div>
			</form>
		</div>
		<script type="text/javascript" src="../../lib/jquery-1.8.3.min.js" ></script>
		<script type="text/javascript" src="../../lib/bootstrap/js/bootstrap.min.js" ></script>
		<script type="text/javascript" src="../../lib/koala-ui.plugin.js" ></script>
		<script>
			$(function() {
				var container = $('.container');
				var file = $('#file').on('change', function(){
					var fileName = $(this).val().split("\\").pop();
					$('#fileName').text(fileName);
				});
				var fileImg = $('#fileImg');
				$('#fileImg').on('click', function() {
					file.click();
				});
				var uploadBtn = $('#uploadBtn');
				var fileName = window.parent.importProject.fileName;
				fileName = fileName.substr(fileName.lastIndexOf('\\') + 1, fileName.length);
				var timestamp = window.parent.importProject.timestamp;
				window.parent.importProject.itemPage.loader('hide').data('koala.loader', null).loader({
					title : '正在解析文件...'
				});
				fileImg.css('visibility', 'hidden');
				uploadBtn.css('visibility', 'hidden');
				$.get('../../project/resolve.koala?timestamp=' + timestamp + '&fileName=' + fileName).done(function(result) {
					window.parent.importProject.itemPage.loader('hide');
					if (result.msg) {
						window.parent.importProject.itemPage.message({
							type : 'error',
							content : result.msg
						});
						window.parent.importProject.baseInfo = null;
						fileImg.css('visibility', 'visible');
						uploadBtn.css('visibility', 'visible');
						$('.title').show();
						$('.title span').text(result.msg)
						$('.title').css('color', '#d2322d').find('i').removeClass('glyphicon-info-sign').addClass('glyphicon-remove-sign');
					} else {
						window.parent.importProject.itemPage.message({
							type : 'success',
							content : '解析文件成功!'
						});
						var baseInfo = {
							projectName : result.name,
							groupId : result.groupId,
							artifactId : result.artifactId,
							version : result.version,
						};
						window.parent.importProject.baseInfo = baseInfo;
						window.parent.importProject.next();
					}
				});
				uploadBtn.on('click', function() {
					var fileName = $('#file').val();
					if (fileName.length == 0) {
						$('body').message({
							type : 'warning',
							content : '请选择要上传的文件!'
						});
						return;
					}
					$('#timestamp').val(new Date().getTime());
					window.parent.importProject.timestamp = $('#timestamp').val();
					window.parent.importProject.fileName = fileName;
					window.parent.importProject.itemPage.data('koala.loader', null).loader({
						title : '正在上传文件...'
					});
					window.parent.importProject.baseInfo = null;
					fileImg.css('visibility', 'hidden');
					$(this).css('visibility', 'hidden');
					$('#form').submit();
				});
			})
		</script>
	</body>
</html>